<%@ page import="com.cinsea.directory.model.Directory" %>
<%@ page import="com.cinsea.directory.service.DirectoryService" %>
<%@ page import="com.cinsea.form.service.FormdataService" %>
<%@ page import="com.cinsea.document.model.Document" %>
<%@ page import="com.cinsea.file.model.Filestore" %>
<%@ page import="com.cinsea.file.service.FilestoreService" %>
<%@ page import="com.cinsea.document.service.DocumentService" %>
<%@ page import="com.cinsea.security.service.RightService" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/common/common.jsp" %>

<%
    String id = StringUtil.null2String(request.getParameter("processid"));

    RightService rightService = (RightService) Env.getBean("rightService");


    DocumentService documentService = (DocumentService) Env.getBean("documentService");
    Document document = documentService.getDocument(id);
    Env.setDowid(document.getDowid());
    Env.setTablename("cs_document");
    boolean opttype = rightService.checkOpttype(id, OptType.VIEW);
    if (!opttype) {
        response.sendRedirect(request.getContextPath() + "/nopermit.jsp?processid="+id);
        return;
    }


    if (!StringUtil.isEmpty(document.getContent())) {
        //return;
    }
    OrgService orgService = (OrgService) Env.getBean("orgService");
    boolean useRTX = false;
    Globalsetting rtxSet = globalsettingService.getSetting("7");
    if (rtxSet != null && "1".equals(rtxSet.getObjvalue())) {
        useRTX = true;
    }

    DirectoryService directoryService = (DirectoryService) Env.getBean("directoryService");
    FilestoreService filestoreServiceice = (FilestoreService) Env.getBean("filestoreService");
    HumanService humanService = (HumanService) Env.getBean("humanService");
    LogService logService = (LogService) Env.getBean("logService");
    String action = request.getContextPath() + "/document.do?action=replydocs";
    String actionversion = request.getContextPath() + "/document.do?action=versioninfo";

    if (document.getDeleted().intValue() == 1) {
%>
<script language='javascript'>
    alert('该文档已经删除');
    if (window.opener != null || window.dialogArguments != null) {//关闭窗口
        self.close();
    }
</script>

<%
        return;
    }
    Log log = new Log();
    log.setLogdesc("操作日志");
    log.setLogtype("85");
    log.setObjid(document.getId());
    log.setObjname(document.getSubject());
    log.setSubmitdate(DateUtil.getCurrentDate());
    log.setSubmittime(DateUtil.getCurrentTime());

    log.setSubmitor(loginUser.getId());
    log.setSubmitip(loginUser.getRemoteIpAddress());

    logService.createLog(log);
    String attachid = StringUtil.trimToNull(request.getParameter("attachid"));
    Filestore filestore = null;
    if (attachid != null) {
        filestore = filestoreServiceice.getAttach(attachid);
    }
    if (filestore == null) {
        Doccontent doccontentt = documentService.getDoccontentLastVerList(id);
        if (doccontentt != null) {
            filestore = filestoreServiceice.getAttach(doccontentt.getFileid());
        }
    }
    int docType = document.getDoctype().intValue();
    String doctypestr = "";
    if (docType == 102)
        doctypestr = "doc";
    if (docType == 103)
        doctypestr = "xls";

    String attachstr = (filestore == null ? "" : filestore.getId());


//附件操作权限

    long righttype = rightService.getOpttype(document.getId());
%>
<!--页面菜单开始-->
<%
    paravaluehm.put("{id}", id);
    paravaluehm.put("{directoryid}", document.getDirectoryid());
    paravaluehm.put("{docType}", new Integer(docType).toString());
    paravaluehm.put("{attachstr}", attachstr);
    PageextendService _pageextendService2 = (PageextendService) Env.getBean("pageextendService");
    if (righttype % 15 == 0)
        pagemenustr += "addBtn(tb,'" + I18n.getText("edit") + "','E','accept',function(){onModify('" + id + "','" + new Integer(docType).toString() + "','" + attachstr + "')});";
    ArrayList<String> menuList = _pageextendService2.getPageextendStrExt(theuri, paravaluehm);
    pagemenustr += menuList.get(0);
    if (righttype % 15 == 0 && (docType == 102 || docType == 103)) {
        pagemenustr += "addBtn(tb,'" + I18n.getText("savelocal") + "','L','save',function(){javascript:savelocalFile()});";
    }
    String docstatusstr = "";
    if ("1".equals(document.getDocstatus().toString())) {
        docstatusstr = I18n.getText("normal");
    }
    if ("0".equals(document.getDocstatus().toString())) {
        docstatusstr = I18n.getText("draft");
    }
%>
<html>
<head>
<%@include file="/common/head.jsp" %>
<%
    if (docType == 102 || docType == 103) {
%>

<SCRIPT language=javascript event=NotifyCtrlReady for=WebOffice1>
    /****************************************************
     *
     *    在装载完Weboffice(执行<object>...</object>)
     *    控件后执行 "WebOffice1_NotifyCtrlReady"方法
     *
     ****************************************************/
    WebOffice1_NotifyCtrlReady()
</SCRIPT>

<SCRIPT language=javascript>
    /****************************************************
     *
     *        控件初始化WebOffice方法
     *
     ****************************************************/
    function WebOffice1_NotifyCtrlReady() {
        document.all.officediv.style.height=(Ext.getBody().getSize().height-60)+'px';
        document.all.WebOffice1.style.height=(Ext.getBody().getSize().height-20)+'px';
        document.all.WebOffice1.OptionFlag |= 128;
        document.all.WebOffice1.OptionFlag &= 0xff7f;
        document.all.WebOffice1.HideMenuItem(0x01+0x02+0x04+0x10+0x20);
        //document.all.WebOffice1.ShowToolBar(0);
        document.all.WebOffice1.ReadOnly=1;
        document.all.WebOffice1.LoadOriginalFile("<%="http://"+request.getServerName()+":"+request.getServerPort()%>/office.do?action=downloadofficedoc&attachid=<%=filestore.getId()%>", "<%=doctypestr%>");
    <%if(righttype%15==0){%>
        //document.all.WebOffice1.SetSecurity(0x01);//print
        //document.all.WebOffice1.SetSecurity(0x04); //copy

    <%}%>
    }

</script>
<%}%>
<style type="text/css">
    a {
        color: blue;
        cursor: pointer;
    }

    .x-layout-collapsed {
        z-index: 20;
        border-bottom: #98c0f4 0px solid;
        position: absolute;
        border-left: #98c0f4 0px solid;
        overflow: hidden;
        border-top: #98c0f4 0px solid;
        border-right: #98c0f4 0px solid
    }
</style>
<script type="text/javascript" src="${ctx}/js/ext/ux/toolbar.js"></script>

<script type="text/javascript">
var grid;
var gridversion;
var sm = new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn});
var contentPanel = null;
var viewport = null;
Ext.onReady(function() {

    Ext.QuickTips.init();
<%if(!pagemenustr.equals("")){%>
    var tb = new Ext.Toolbar({id:'toolbar1'});
    tb.render('pagemenubar');
<%=pagemenustr%>
<%}%>
    // create the data store
    var strTable = "<table><tr>";
    strTable = "<td width='105px'>&nbsp;&nbsp;<a><img align='absmiddle' src='${ctx}/images/silk/application_osx.gif'> <b><%=I18n.getText("document")%><%=I18n.getText("property")%> &nbsp;&nbsp;&nbsp;</b></a></td>" +
            "<td width='16px'></td>" +
            "</tr></table> ";

    var tt = new Ext.Template(
            '<div  style="width:100%;cursor:pointer;border-bottom:#98c0f4 1px solid;height: 22px; border-right:#98c0f4 1px solid;border-left:#98c0f4 1px solid;border-top:#98c0f4 1px solid;" ><div style="float:left">' + strTable + '</div><div class="x-tool x-tool-expand-south" style="height:14px"></div></div>'
            );
    tt.disableFormats = true;
    tt.compile();
    Ext.override(Ext.layout.BorderLayout.Region, {
        toolTemplate:tt
    });
    var store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '<%=action%>'
        }),
        reader: new Ext.data.JsonReader({
            root: 'result',
            totalProperty: 'totalcount',
            fields: ['subject','createdate','humanname','attachnum','status','directoryname','content']


        })

    });
    var versionstore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '<%=actionversion%>'
        }),
        reader: new Ext.data.JsonReader({
            root: 'result',
            totalProperty: 'totalcount',
            fields: ['versioninfo','rollback','look','delete']


        })

    });
    // create the Grid
    var cmversion = new Ext.grid.ColumnModel([
   
        {
            header: "<%=I18n.getText("version")%>",
            width:300,
            dataIndex: 'versioninfo'
        },
        {
            header: "<%=I18n.getText("action")%>",
            width:100,
            dataIndex: 'rollback'
        },
        {
            header: "<%=I18n.getText("action")%>",
            width:100,
            dataIndex: 'look'
        },
        {
            header: "<%=I18n.getText("action")%>",
            width:100,
            dataIndex: 'delete'
        }
    ]);
    var cm = new Ext.grid.ColumnModel([
        {
            header: "<%=I18n.getText("title")%>",
            width:300,
            dataIndex: 'subject'
        },
        {
            header: "<%=I18n.getText("createdate")%>",
            width:100,
            dataIndex: 'createdate'
        },
        {
            header: "<%=I18n.getText("creator")%>",
            width:100,
            dataIndex: 'humanname'
        },
        {
            header: "<%=I18n.getText("filestore")%><%=I18n.getText("amount")%>",
            width:200,
            dataIndex: 'attachnum'
        },
        {
            header: "<%=I18n.getText("status")%>",
            width:100,
            dataIndex: 'status'
        } ,
        {
            header: "<%=I18n.getText("directory")%>",
            width:200,
            dataIndex: 'directoryname'
        },
        {
            header: "<%=I18n.getText("abstract")%>",
            width:100,
            dataIndex: 'content'
        }
    ]);
    grid = new Ext.grid.GridPanel({
        //region: 'center',
        store: store,
        cm: cm,
        trackMouseOver:false,
        height:350,
        loadMask: true,
        title:'<%=I18n.getText("reply")%><%=I18n.getText("info")%>',
        viewConfig: {
            //  forceFit:true,
            enableRowBody:true,
            sortAscText:'<%=I18n.getText("sortAscText")%>',
            sortDescText:'<%=I18n.getText("sortDescText")%>',
            columnsText:'<%=I18n.getText("columnsText")%>',
            getRowClass : function(record, rowIndex, p, store) {
                return 'x-grid3-row-collapsed';
            }
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 20,
            store: store,
            displayInfo: true,
            beforePageText:'<%=I18n.getText("beforePageText")%>',
            afterPageText:'<%=I18n.getText("afterPageText")%>',
            firstText:'<%=I18n.getText("firstText")%>',
            prevText:'<%=I18n.getText("prevText")%>',
            nextText:'<%=I18n.getText("nextText")%>',
            lastText:'<%=I18n.getText("lastText")%>',
            displayMsg:'<%=I18n.getText("displayMsg")%>',
            emptyMsg:'<%=I18n.getText("emptyMsg")%>'
        })

    });
    gridversion = new Ext.grid.GridPanel({
        //region: 'center',
        store: versionstore,
        cm: cmversion,
        title:'<%=I18n.getText("version")%>',
        trackMouseOver:false,
        sm:sm ,
        height:350,
        loadMask: true,
        viewConfig: {
            //  forceFit:true,
            enableRowBody:true,
            sortAscText:'<%=I18n.getText("sortAscText")%>',
            sortDescText:'<%=I18n.getText("sortDescText")%>',
            columnsText:'<%=I18n.getText("columnsText")%>',
            getRowClass : function(record, rowIndex, p, store) {
                return 'x-grid3-row-collapsed';
            }
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 20,
            store: store,
            displayInfo: true,
            beforePageText:'<%=I18n.getText("beforePageText")%>',
            afterPageText:'<%=I18n.getText("afterPageText")%>',
            firstText:'<%=I18n.getText("firstText")%>',
            prevText:'<%=I18n.getText("prevText")%>',
            nextText:'<%=I18n.getText("nextText")%>',
            lastText:'<%=I18n.getText("lastText")%>',
            displayMsg:'<%=I18n.getText("displayMsg")%>',
            emptyMsg:'<%=I18n.getText("emptyMsg")%>'
        })

    });
    versionstore.baseParams.objid = '<%=id%>'
    versionstore.load({params:{start:0, limit:<%=20%>},paged:""});
    // gridversion.render('versioninfo')
    store.baseParams.objid = '<%=id%>';
    store.load({params:{start:0, limit:<%=20%>},paged:""});
    // grid.render('docreplay');
    contentPanel = new Ext.TabPanel({
        border:false,
        activeTab:0,
        tabPosition:'bottom',
        items:[
            {
                contentEl:'docattribute',
                title: '<%=I18n.getText("base")%><%=I18n.getText("property")%>',
                autoScroll:true
            },
            grid,
            <%if(righttype%15==0){%>
            gridversion,
            <%}%>
            {
                title: '<%=I18n.getText("remark")%>',
                closable:false,
                xtype     :'iframepanel',
                frameConfig: {
                    autoCreate:{
                        frameborder:0
                    },
                    eventsFollowFrameLinks : false
                },
                defaultSrc:' ${ctx}/document/remarkcreate.jsp?objid=<%=id%>',
                autoScroll:true
            },
            {
                title: '<%=I18n.getText("remark")%><%=I18n.getText("detail")%>',
                closable:false,
                xtype     :'iframepanel',
                frameConfig: {
                    autoCreate:{
                        frameborder:0
                    },
                    eventsFollowFrameLinks : false
                },
                defaultSrc:'${ctx}/document/remarklist.jsp?objid=<%=id%>',
                autoScroll:true
            },
            {
                title: '<%=I18n.getText("statistics")%>',
                closable:false,
                xtype     :'iframepanel',
                frameConfig: {
                    autoCreate:{
                        frameborder:0
                    },
                    eventsFollowFrameLinks : false
                },
                defaultSrc:'${ctx}/document/docscore.jsp?objid=<%=id%>&dowid=<%=document.getDowid()%>',
                autoScroll:true
            }
        ]
    });
    viewport = new Ext.Viewport({
        layout: 'border',
        items:[
            {region:'north',items:[tb],height:26},
            {
                region: 'center',
                contentEl: 'content'<%if(docType == 101){%>,
                autoScroll:true
                <%}%>
                <%if(docType == 102||docType==103){%>,
                autoScroll:false
                <%}%>
            },
            {
                region:'south',
                title:'<%=I18n.getText("document")%><%=I18n.getText("property")%>',
                collapsible: true,
                split:true,
                width: 225,
                height:140,
                collapsed:false,
                id:'divformcontentPanel',
                layout:'fit',
                items:contentPanel
            }
        ]
    });

});
</script>
</head>
<body onunload="CloseWord()">
<div id="pagemenubar"></div>

<!--页面菜单结束-->

<!-- 正文 -->

<div id="content">


                    <%if(filestore!=null&&filestore.getObjpath()!=null){
						if(docType==101){%>
       <table id="contentDiv" class=noborder>
        <tbody>
        <tr>
            <td valign=top>
                <!--html显示模板开始-->
                <TABLE class=text height="294" cellSpacing=0 cellPadding=0 width="100%"
                       border=0>
                    <TBODY>
                    <TR>
                        <TD width=24 height=18><font face="Arial"> </font></TD>
                        <TD width=891 height=18><font face="Arial">
                            <FONT color=#dc143c><FONT color=#000000><FONT size=1>文档编号：<%=document.getObjno()%>
                            </FONT> <BR></FONT>
                                <FONT color=#000000 size=1>发布日期：<%=document.getCreatedate()%>
                                </FONT> </FONT></FONT></font>
                        </TD>

                        <TD colSpan=2 height=18>
                        </TD>
                    </TR>
                    <TR>
                        <TD width=24 ><font face="Arial"> </font></TD>
                        <TD vAlign=top >
                            <p><STRONG>
                                <FONT face=Arial><BR>
                                </FONT></STRONG><FONT
                                    color=#000000><FONT face=Arial>
                            </FONT></FONT>
                            </p>

                            <P align=center>
                                <FONT color=black size=5><STRONG><%=document.getSubject()%>
                                </STRONG><BR></FONT>
                                创建人：<FONT color=crimson><a
                                    href="javascript:onUrl('${ctx}/form/formprocess.jsp?processid=<%=document.getCreator()%>','<%=humanService.getHumanById(document.getCreator()).getObjname()%>','tab<%=document.getCreator()%>')"><%=humanService.getHumanById(document.getCreator()).getObjname()%>
                            </a></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                部门：<FONT color=crimson><a
                                    href="javascript:onUrl('${ctx}/hrm/orgview.jsp?id=<%=humanService.getHumanorg(document.getCreator())%>','<%=orgService.getOrg(humanService.getHumanorg(document.getCreator())).getObjname()%>','tab<%=humanService.getHumanorg(document.getCreator())%>')"><%=orgService.getOrg(humanService.getHumanorg(document.getCreator())).getObjname()%>
                            </a></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                状态：<FONT size=2><FONT color=#dc143c><%=docstatusstr%>
                            </FONT></FONT></P>

                            <div class="fckContent">
                                <P align=left>
                                    <%=documentService.getDocContent(document.getId(), attachid)%>
                                </p>
                            </div>
                            <div></div>
                            <P align=left></P>

<!--                             <P align=right>
                                <%=humanService.getHumanById(document.getCreator()).getObjname()%><BR>
                                <%=document.getCreatedate()%>
                            </P> -->

                            <P><br>
                                <br>
                                <br></P>

                            <p>　</p>
                        </TD>
                        <TD width=19 >　</TD>
                        <TD vAlign=bottom align=left width=69>
                        </TD>
                    </TR>

                    </TBODY>
                </TABLE>
        <!--html显示模板结束-->
         </td>
        </tr>
        </tbody>
    </table>
        <%} else if (docType == 102 || docType == 103) {%>
        <div id='officediv' style="POSITION: relative;width:100%;overflow:hidden;">
            <object id="WebOffice1" style="POSITION: relative;top:-35" width=100%
                    classid="clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5"
                    codebase="<%=request.getContextPath() %>/plugin/weboffice_v7.0.0.0.cab#version=7,0,0,0">
                <param name="_ExtentX" value="6350">
                <param name="_ExtentY" value="6350">
            </object>
        </div>
        <%
                }
            }
        %>

</div>

<!-- 版本信息 start -->

<div id="versioninfo">

</div>

<!-- 文档回复 start -->
<%
    Document maindocument = documentService.getMainDocument(id);
    String dowid = maindocument.getDowid();
%>
<div id="docreplay"></div>


<!-- 文档属性页 start -->

<div id="docattribute">


    <%
        Directory directory = directoryService.getDirectoryById(dowid);
        String formcontent = "";
        Map parameters = new HashMap();
        parameters.put("dowid", dowid);
        parameters.put("processtype", "2");
        parameters.put("formviewtype", "1");
        parameters.put("onlyread", "1");
        parameters.put("formid", "cs_document");
        parameters.put("processid", id);
        parameters.put("object", document);
        parameters.put("viewid", directory.getPReadviewid());

        FormdataService fs = (FormdataService) Env.getBean("formdataService");
        parameters = fs.getFormdata(parameters);

        formcontent = StringUtil.null2String(parameters.get("formcontent"));
        if (formcontent.equals("") && docType == 3)
            formcontent = "<b><font color=red>没有定义对应的视图，请和系统管理员联系！</font></a>";

    %>

    <%=formcontent%>

</div>
<!-- 点评 -->
<!--文章推荐或点评开始-->


<!--文章推荐或点评结束 -->


<script language="javascript">


    function onModify(id, doctype, attachid) {

        if (doctype == 101) {
            var url = "documentmodify.jsp?processid=" + id + "&attachid=" + attachid;
        } else if (doctype == 102 || doctype == 103) {
            var url = "documentmodify1.jsp?processid=" + id + "&attachid=" + attachid;
        }
        window.location.href = url;
    }
    function onRepay(pid) {
        var url = "documentcreate.jsp?pid=" + pid + "&directoryid=<%=dowid%>";
        window.location.href = url;
    }
    //作用：保存office正文到本地

    function savelocalFile() {
        try {
            var webObj = document.getElementById("WebOffice1");
            webObj.ShowDialog(84);
        } catch(e) {
            alert("异常\r\nError:" + e + "\r\nError Code:" + e.number + "\r\nError Des:" + e.description);
        }
    }

</script>
<script type="text/javascript">
    function getVersion(docid) {
        var url = "${ctx}/document/documentversion.jsp?id=" + docid;
        try {
            id = showDialog(url);
        } catch(e) {
        }
        if (id != null) {
            if (id[0] != '0') {
                window.location.href = "documentview.jsp?processid=" + id[0] + "&attachid=" + id[1]
            } else {
                window.location.href = "documentview.jsp?processid=" + docid

            }
        }
    }

    function onDelete(id) {
        yes('<%=I18n.getText("deleteConfirm")%>', function() {
            Ext.Ajax.request({
                url:'${ctx}/formdata.do?action=delete',
                sync:true,
                params:{processid:'<%=id%>'},
                success: function(res) {
                    var result = res.responseText;
                    if (result == 'success') {
                        var tabpanel = top.contentPanel;
                        tabpanel.remove(tabpanel.getActiveTab());
                    } else {
                        pop(result)
                    }
                }
            });
        })
    }
    function onOpenWindow(url) {
        window.open(url, "newdocwindow", "height=600, width=900, top=0, left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=yes");
    }
    function openchild(inputvalue) {
        var returnvalue = new String(showDialog("${ctx}/document/basechild.jsp?objid=" + inputvalue, "Width=110,Height=100"));
    }


    function selectVersion(id) {
        window.location.href = "${ctx}/document.do?action=selectver&processid=<%=id%>&ver=" + id;
    }
    function deleteVersion(id) {
        window.location.href = "${ctx}/document.do?action=deletever&processid=<%=id%>&ver=" + id;
    }
    function openVersion(id) {
        window.location.href = "${ctx}/document/documentview.jsp?processid=<%=id%>&attachid=" + id;
    }
    function CloseWord() {
                    if(document.all&&document.all.WebOffice1)
                    document.all.WebOffice1.Close(0);
                }
</script>

</body>
</html>
